import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

/* Layout */
import Layout from '@/layout';

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () =>
      import(/* webpackChunkName:"login"*/ '@/views/login/index'),
    name: '登陆',
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Layout布局',
    children: [
      {
        path: '/dashboard',
        component: () =>
          import(/* webpackChunkName:"Layout"*/ '@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   name: 'Layout布局',
  //   children: [
  //     {
  //       path: '/clue/clue-1/add',
  //       component: () => import(/* webpackChunkName:"clue-add"*/ '@/views/clue/clue-1/add-page'),
  //       name: '录入线索',
  //       meta: { title: '录入线索', icon: 'dashboard', affix: true }
  //     }
  //   ]
  // },
  {
    path: '/404',
    component: () => import(/* webpackChunkName:"404"*/ '@/views/404'),
    hidden: true
  },
  {
    path: '*',
    component: () => import('@/views/404'),
    hidden: true
  }
];

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 个人信息，每个必有返回，否则报错，会循环获取菜单（已解决）
  {
    path: '/userinfo',
    component: () =>
      import(/* webpackChunkName:"UserInfo"*/ '@/views/userinfo/UserInfo')
  },

  // 公共中间路由
  {
    path: '/middle-menu',
    component: () => import('@/components/PublicMiddleMenu/PublicMiddleMenu')
  },

  // 超级管理员
  {
    path: '/super',
    component: Layout,
    redirect: '/super/user',
    name: '超管-系统管理',
    meta: {
      title: '超管-系统管理',
      icon: 'dashboard'
    },
    children: [
      {
        path: '/super/user',
        component: () => import('@/views/super/user/index'),
        name: '用户管理',
        meta: {
          title: '用户管理',
          icon: 'dashboard'
        }
      },
      {
        path: '/super/role',
        component: () => import('@/views/super/role/index'),
        name: '角色管理',
        meta: {
          title: '角色管理',
          icon: 'dashboard'
        }
      },
      {
        path: '/super/menu',
        component: () => import('@/views/super/menu/index'),
        name: '菜单管理',
        meta: {
          title: '菜单管理',
          icon: 'dashboard'
        }
      },
      {
        path: '/super/area',
        component: () => import('@/views/super/area/index'),
        name: '地域管理',
        meta: {
          title: '地域管理',
          icon: 'dashboard'
        }
      }
    ]
  },

  // 普通管理员
  {
    path: '/system/user',
    component: () => import('@/views/system/user/index'),
    name: '用户管理',
    meta: {
      title: '用户管理',
      icon: 'dashboard'
    }
  },
  {
    path: '/system/area',
    component: () => import('@/views/system/area/index'),
    name: '地域管理',
    meta: {
      title: '地域管理',
      icon: 'dashboard'
    }
  },
  {
    path: '/system/role',
    component: () => import('@/views/system/role/index'),
    name: '角色管理',
    meta: {
      title: '角色管理',
      icon: 'dashboard'
    }
  },
  {
    path: '/system/menu',
    component: () => import('@/views/system/menu/index'),
    name: '菜单管理',
    meta: {
      title: '菜单管理',
      icon: 'dashboard'
    }
  },

  // 线索征集管理路由
  // 1.征集线索-添加
  {
    path: '/clue/clue-1',
    component: () => import('@/views/clue/clue-1/clue-1'),
    name: '征集线索',
    meta: {
      title: '征集线索',
      icon: 'el-icon-present'
    }
  },
  {
    path: '/clue/clue-add',
    component: () => import('@/views/clue/clue-1/add-page'),
    name: '添加线索',
    meta: {
      title: '添加线索',
      icon: 'el-icon-present'
    }
  },
  // 2.鉴定估价
  {
    path: '/clue/clue-2',
    component: () => import('@/views/clue/clue-2/clue-2'),
    name: '鉴定估价',
    meta: {
      title: '鉴定估价',
      icon: 'el-icon-present'
    }
  },
  // 3.确认征集
  {
    path: '/clue/clue-3',
    component: () => import('@/views/clue/clue-3/clue-3'),
    name: '确认征集',
    meta: {
      title: '确认征集',
      icon: 'el-icon-present'
    }
  },
  // 4.所有征集对象
  {
    path: '/clue/clue-all',
    component: () => import('@/views/clue/clue-all/clue-all'),
    name: '确认征集',
    meta: {
      title: '确认征集',
      icon: 'el-icon-present'
    }
  },
  // 藏品登记
  // 1. 藏品登记
  {
    path: '/clue/register/register',
    component: () => import('@/views/clue/register/register'),
    name: '藏品登记',
    meta: {
      title: '藏品登记',
      icon: 'el-icon-present'
    }
  },
  // 2. 藏品审核
  {
    path: '/clue/register/check',
    component: () => import('@/views/clue/register/check'),
    name: '藏品审核',
    meta: {
      title: '藏品审核',
      icon: 'el-icon-present'
    }
  },
  // 3. 藏品三级审核
  {
    path: '/clue/register/check2',
    component: () => import('@/views/clue/register/ThreeCheck'),
  },
  // 资料参考登记
  // 1. 资料参考登记
  {
    path: '/clue/dataReference/register',
    component: () => import('@/views/clue/dataReference/register'),
    name: '资料参考登记',
    meta: {
      title: '资料参考登记',
      icon: 'el-icon-present'
    }
  },
  // 2.资料参考审核
  {
    path: '/clue/dataReference/check',
    component: () => import('@/views/clue/dataReference/check'),
    name: '资料参考审核',
    meta: {
      title: '资料参考审核',
      icon: 'el-icon-present'
    }
  },
  // 3. 藏品三级审核
  {
    path: '/clue/dataReference/ThreeCheck',
    component: () => import('@/views/clue/dataReference/ThreeCheck'),
  },
  // 藏品提借利用
  // 1. 全部提借
  {
    path: '/clue/borrow/all_borrow',
    component: () => import('@/views/clue/borrow/borrow-all'),
    name: '全部提借',
    meta: {
      title: '全部提借',
      icon: 'el-icon-s-order'
    }
  },
  // 2. 我的已归库
  {
    path: '/clue/borrow/borrow-already',
    component: () => import('@/views/clue/borrow/borrow-already'),
    name: '我的已归库',
    meta: {
      title: '我的已归库',
      icon: 'el-icon-s-order'
    }
  },
  // 3. 我的待归库
  {
    path: '/clue/borrow/borrow-wait',
    component: () => import('@/views/clue/borrow/borrow-wait'),
    name: '我的待归库',
    meta: {
      title: '我的待归库',
      icon: 'el-icon-s-order'
    }
  },
  // 4. 我的待出库
  {
    path: '/clue/borrow/borrow-wait-out',
    component: () => import('@/views/clue/borrow/borrow-wait-out'),
    name: '我的待出库',
    meta: {
      title: '我的待出库',
      icon: 'el-icon-s-order'
    }
  },
  // 5. 我的提借单
  {
    path: '/clue/borrow/borrow-mine',
    component: () => import('@/views/clue/borrow/borrow-mine'),
    name: '我的提借单',
    meta: {
      title: '我的提借单',
      icon: 'el-icon-s-order'
    }
  },

  // 藏品统计管理
  // 1. 藏品来源统计
  {
    path: '/clue/statistics/sourceStatistics',
    component: () => import('@/views/clue/statistics/sourceStatistics'),
    name: '藏品来源统计',
    meta: {
      title: '藏品来源统计',
      icon: 'el-icon-s-data'
    }
  },
  // 2. 藏品年代统计
  {
    path: '/clue/statistics/yearStatistics',
    component: () => import('@/views/clue/statistics/yearStatistics'),
    name: '藏品年代统计',
    meta: {
      title: '藏品年代统计',
      icon: 'el-icon-s-data'
    }
  },
  // 3. 藏品展示次数统计
  {
    path: '/clue/statistics/showNumberStatistics',
    component: () => import('@/views/clue/statistics/showNumberStatistics'),
    name: '藏品展示次数统计',
    meta: {
      title: '藏品展示次数统计',
      icon: 'el-icon-s-data'
    }
  },
  // 4. 藏品入藏时间统计
  {
    path: '/clue/statistics/inTimeStatistics',
    component: () => import('@/views/clue/statistics/inTimeStatistics'),
    name: '藏品入藏时间统计',
    meta: {
      title: '藏品入藏时间统计',
      icon: 'el-icon-s-data'
    }
  },
  // 5. 藏品类型统计
  {
    path: '/clue/statistics/typeStatistics',
    component: () => import('@/views/clue/statistics/typeStatistics'),
    name: '藏品类型统计',
    meta: {
      title: '藏品类型统计',
      icon: 'el-icon-s-data'
    }
  },
  // -----
  {
    path: '/library/index',
    component: () => import('@/views/library/index'),
    name: '柜架设置',
    meta: {
      title: '柜架设置',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/enterMuseum/enterAccount',
    component: () => import('@/views/enterMuseum/enterAccount'),
    name: '藏品入账',
    meta: {
      title: '藏品入账',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/enterMuseum/inventoryManagement',
    component: () => import('@/views/enterMuseum/inventoryManagement'),
    name: '编目管理',
    meta: {
      title: '编目管理',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/enterMuseum/confirmEnterMuseum',
    component: () => import('@/views/enterMuseum/confirmEnterMuseum'),
    name: '确认入藏',
    meta: {
      title: '确认入藏',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/enterMuseum/enterAccountMany',
    component: () => import('@/views/enterMuseum/enterAccountMany'),
    name: '藏品批量入账',
    meta: {
      title: '藏品批量入账',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/log/date',
    component: () => import('@/views/log/date'),
    name: '新增日志',
    meta: {
      title: '新增日志',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/log/logManagement',
    component: () => import('@/views/log/logManagement'),
    name: '日志管理',
    meta: {
      title: '日志管理',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/log/putApplication',
    component: () => import('@/views/log/putApplication'),
    name: '入库申请',
    meta: {
      title: '入库申请',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/log/putAudit',
    component: () => import('@/views/log/putAudit'),
    name: '入库审核',
    meta: {
      title: '入库审核',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/log/putDeal',
    component: () => import('@/views/log/putDeal'),
    name: '入库处理',
    meta: {
      title: '入库处理',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/log/archiveQuery',
    component: () => import('@/views/log/archiveQuery'),
    name: '归档查询',
    meta: {
      title: '归档查询',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/collectionManage/registration',
    component: () => import('@/views/collectionManage/registration'),
    name: '物品登记管理',
    meta: {
      title: '物品登记管理',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/collectionManage/put',
    component: () => import('@/views/collectionManage/put'),
    name: '物品入库管理',
    meta: {
      title: '物品入库管理',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/collectionManage/outband',
    component: () => import('@/views/collectionManage/outband'),
    name: '物品出库管理',
    meta: {
      title: '物品出库管理',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/collectionManage/query',
    component: () => import('@/views/collectionManage/query'),
    name: '物品查询',
    meta: {
      title: '物品查询',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/collectionManage/move',
    component: () => import('@/views/collectionManage/move'),
    name: '物品移动管理',
    meta: {
      title: '物品移动管理',
      icon: 'el-icon-s-data'
    }
  },
  {
    path: '/collectionManage/moveLog',
    component: () => import('@/views/collectionManage/moveLog'),
    name: '物品移动历史查询',
    meta: {
      title: '物品移动历史查询',
      icon: 'el-icon-s-data'
    }
  },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
